digits = "23"

var hash = {
    '2': ['a', 'b', 'c'],
    '3': ['d', 'e', 'f'],
    '4': ['g', 'h', 'i'],
    '5': ['j', 'k', 'l'],
    '6': ['m', 'n', 'o'],
    '7': ['p', 'q', 'r', 's'],
    '8': ['t', 'u', 'v'],
    '9': ['w', 'x', 'y', 'z']
}

var letterCombinations = function (digits) {
    if (digits === "") {
        return []
    }
    let result = []
    let str = ''

    function dfs(index) {
        if (index === digits.length) {
            result.push(str)
            return;
        }

        hash[digits[index]].forEach(item => {
            str += item
            dfs(index + 1)
            str = str.slice(0, -1)
        })
    }

    dfs(0)
    return result
};